package com.cams.backend.controller;


import com.cams.backend.common.lang.Result;
import com.cams.backend.entity.Leaves;
import com.cams.backend.service.LeavesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cams
 * @since 2022-05-20
 */
@RestController
@RequestMapping("/leaves")
public class LeavesController {

    @Autowired
    LeavesService leavesService;

    /**
     * 请假申请
     * 交互接口
     * @author chs
     */
    @PostMapping("/apply")
    public Result apply(@RequestBody Leaves leaves){
        return leavesService.apply(leaves);

    }

    /**
     * 查看所有请假申请(无条件查询)
     * 交互接口
     * @author chs
     */
    @GetMapping("/check/all")
    public Result leaveCheckAll(){
        return leavesService.leaveCheckAll();
    }

    /**
     * 查看某用户请假申请(使用uid)
     * 交互接口
     * @author chs
     */
    @GetMapping("/check/{uid}")
    public Result leaveCheckByUid(@PathVariable("uid") int uid){
        return leavesService.leaveCheckByUid(uid);
    }

    /**
     * 请假审批
     * 交互接口
     * @author chs
     */
    @PostMapping("/approve")
    public Result approve(@RequestBody Leaves leaves){
        return leavesService.approve(leaves);

    }

    /**
     * 删除请假申请
     * 交互接口
     * @author chs
     */
    @DeleteMapping  ("/delete/{lid}")
    @ResponseBody
    public Result deleteLeaveByLid(@PathVariable("lid") int lid){
        return leavesService.deleteLeaveByLid(lid);
    }

}
